/**
 *   \file myex01.c
 *   \brief A Documented file.
 *
 *  compile with: gcc -g -Wall myex01.c -o myex01 -lvirt
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <libvirt/libvirt.h>

int main(int argc, char *argv[])
{
    virConnectPtr  conn;
    virDomainPtr  *domains;
    size_t         i;
    int            ret;
    unsigned int   flags = VIR_CONNECT_LIST_DOMAINS_RUNNING |
      VIR_CONNECT_LIST_DOMAINS_PERSISTENT;

    conn = virConnectOpen("qemu:///system");
    if (conn == NULL) {
      fprintf(stderr, "Failed to connection to qemu:///system\n");
      return 1;
    }

    ret = virConnectListAllDomains(conn, &domains, flags);
    if (ret < 0) {
      fprintf(stderr, "Failed to list all domains\n");
      return 1;
    }

    virConnectClose(conn);
    return 0;
}
